package Servlet.AdminServlet;

import Entity.Course;
import Entity.Student;
import Service.AdminService.AdminService;
import Util.ReadJsonString;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
/*
负责管理员 删除学生 数据接口
 */
@WebServlet(value = "/adminDeleteStudent")
public class AdminDeleteStudent extends HttpServlet {
    private AdminService adminService = new AdminService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json; charset=utf-8");

        /*
        前端发送Json数据 需要从request 流中解析成Json处理
         */
        String json = ReadJsonString.readJSONString(request);


                /*
        json文本解析成Json对象
         */
         List<Student> studentList = JSON.parseArray(json, Student.class);



        int successCount = adminService.adminDeleteStudent(studentList);


        PrintWriter out = response.getWriter();

        out.print(successCount);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
